package com.bocai.eelly.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bocai.eelly.R;
import com.bocai.eelly.bean.HuodaiListBean;
import com.bocai.eelly.utils.TimeUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2016/5/30.
 */
public class HuodaiInquiryAdp extends BaseAdapter {
    private Context context;
    private List<HuodaiListBean.DataEntity> dataEntities=new ArrayList<>();
    public HuodaiInquiryAdp(Context context,List<HuodaiListBean.DataEntity> dataEntities) {
        this.context = context;
        this.dataEntities=dataEntities;
    }

    @Override
    public int getCount() {
        return dataEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return dataEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.find_order_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvFindOrderNameTitle.setText("目的港");
        viewHolder.tvFindOrderMaterialTitle.setText("运输");
        viewHolder.tvFindOrderNum.setText("货物名称："+dataEntities.get(position).getName());
        viewHolder.tvFindOrderName.setText(dataEntities.get(position).getDestination_port());
        viewHolder.tvFindOrderMaterial.setText(dataEntities.get(position).getTransport_mode());
        viewHolder.tvFindOrderTime.setText(TimeUtils.getMonth(Long.parseLong(dataEntities.get(position).getTimeline())));
        viewHolder.tvFindOrderCity.setText(dataEntities.get(position).getCity());
        return convertView;
    }



    class ViewHolder {
        @Bind(R.id.tv_find_order_num)
        TextView tvFindOrderNum;
        @Bind(R.id.tv_find_order_name_title)
        TextView tvFindOrderNameTitle;
        @Bind(R.id.tv_find_order_name)
        TextView tvFindOrderName;
        @Bind(R.id.tv_find_order_material_title)
        TextView tvFindOrderMaterialTitle;
        @Bind(R.id.tv_find_order_material)
        TextView tvFindOrderMaterial;
        @Bind(R.id.tv_find_order_time)
        TextView tvFindOrderTime;
        @Bind(R.id.tv_find_order_city)
        TextView tvFindOrderCity;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
